include metasprites3.s
include bytecode_asm.s
include decompress_tiles.s
include scenes.s
include map2.s

; -----------------------------------------
; these don't seem to work
dcompare: ; n16 n16 -- result16
	tsx
	sec
	sbc $102,x
	sta $102,x
	pla
	sbc $102,x
	sta $102,x
	pla
	vmnext

dless:   ; n16 n16 -- flag
	colon
	mcallasm dcompare ; result16
	.dw droplit, $7f, ugreater, exit

dgreater:   ; n16 n16 -- flag
	colon
	mcallasm dcompare ; result16
	.dw droplit, $80, uless, exit
; -----------------------------------------

align 2

cloud: colon
	mif +then
		mcallasm xfetch
		.dw twolit, $0003, dplus
		.dw over, lit, $0f, greater
		mif ++then
			.dw drop, droptwolit, $ff80
		++then
		mcallasm xstore
		mcallasm yfetch
		.dw twolit, $fff8, dplus
		.dw over, lit, $ff, less
		mif ++then
			.dw drop, droptwolit, $0a00
		++then
		mcallasm ystore
	+then
	mcallasm screenxy
	mdouble ms_cloud_0
	mcallasm metaspr
	.dw exit

starting_obj_positions:
	.db 8,8,1,3,5,9


align 4
water_cycle_data:
	.db $2c, $1c, $3c, $30
	.db $1c, $3c, $30, $2c
	.db $3c, $30, $2c, $1c
	.db $30, $2c, $1c, $3c

waterpalofs:
	pha
	lda FRAMECNT
	cmp $80
	ror a
	cmp $80
	ror a
	cmp $80
	ror a
	and #3
	asl a
	asl a
	vmnext

water_color_cycle: colon
	.dw twolit, water_cycle_data, waterpalofs, plus, astore
	.dw lit, 5, updpal
	.dw exit

oamattr:
	sta OAM_ATTR_FLAGS
	vmnext_pla


; probably just going to go with one or two clouds and when they go off the top of the screen,
;  relocate them below water (avoiding flowers?)
doclouds:
	colon
	mcallasm everyother
	.dw dup
	mcall cloud
	.dw oplus
	.dw lit, 1, xor
	mcall cloud
	.dw oplus
	.dw zero, oamattr
	.dw exit




; include player.s
include script2.s

script_frame: script
	.dw zero, ostore

	mcall doplayer

	;.dw clouds_enabled
	;ifdo doclouds
	;.dw watercycle_enabled
	;ifdo water_color_cycle

;	.dw twolit,$e050,twolit,ms_girl,metaspr

	.dw end


script_init: script

	mdouble starting_obj_positions
	.dw astore
	.dw zero, ostore
	.dw lit, 3

-for .dw for
		.dw fetchplus, zero, xstore, fetchplus, zero, ystore
		.dw oplus
mnext -for

	; load test nametable
;	.dw twolit,testnam,twolit,$2000,decompress_tiles
	; copy chr data to chr ram
;	.dw twolit,chrspr,twolit,$0000,decompress_tiles
;	.dw twolit,chrbg,twolit,$1000,decompress_tiles

	.dw lit,_field1,load_scene

	.dw lit,0,load_screen
	.dw lit,_nullscene,lit,SCENE,store   ; temporary: set null scene, get rid of clouds etc

	.dw end